﻿'******************************* File Header *********************************
'* File Name:    WmiParameterTest.vb
'* Project:      WmiConnection.Test
'* Copyright (c) Freddy Kuehne
'*
'* Unit tests for WmiParameter.
'* 
'* This source is subject to the GNU Library General Public License (LGPL).
'* See http://wmiconnection.codeplex.com/license.
'* All other rights reserved.
'*****************************************************************************
Imports System.Text
Imports System.Data.Common

<TestClass()>
Public Class WmiParameterTest
#Region "Tests"
  <TestMethod()>
  Public Sub Constructor1Test()
    Dim target As New WmiParameter
    Assert.IsNotNull(target)
  End Sub

  <TestMethod()>
  Public Sub Constructor2Test()
    Dim target As New WmiParameter("name", DBNull.Value)
    Assert.AreEqual("name", target.ParameterName)
    Assert.AreEqual(DBNull.Value, target.Value)
  End Sub

  <TestMethod()>
  Public Sub Constructor3Test()
    Dim target As New WmiParameter("name", DbType.String, 24)
    Assert.AreEqual("name", target.ParameterName)
    Assert.AreEqual(DbType.String, target.DbType)
    Assert.AreEqual(24, target.Size)
  End Sub

  <TestMethod()>
  Public Sub HierarchyTest()
    Dim target As New WmiParameter
    Assert.IsInstanceOfType(target, GetType(DbParameter))
  End Sub

  <TestMethod()>
  Public Sub DbTypeTest()
    Dim target As New WmiParameter
    Assert.AreEqual(DbType.Object, target.DbType)
    For Each en As DbType In [Enum].GetValues(GetType(DbType))
      target.DbType = en
      Assert.AreEqual(en, target.DbType)
    Next
  End Sub

  <TestMethod()>
  Public Sub DirectionTest()
    Dim target As New WmiParameter
    Assert.AreEqual(ParameterDirection.Input, target.Direction)
    For Each en As ParameterDirection In [Enum].GetValues(GetType(ParameterDirection))
      target.Direction = en
      Assert.AreEqual(en, target.Direction)
    Next
  End Sub

  <TestMethod()>
  Public Sub IsNullableTest()
    Dim target As New WmiParameter
    Assert.IsTrue(target.IsNullable)
    target.IsNullable = False
    Assert.IsFalse(target.IsNullable)
  End Sub

  <TestMethod()>
  Public Sub ParameterNameTest()
    Dim target As New WmiParameter
    Assert.IsNull(target.ParameterName)
    target.ParameterName = "name"
    Assert.AreEqual("name", target.ParameterName)
    target.ParameterName = String.Empty
    Assert.AreEqual(String.Empty, target.ParameterName)
    target.ParameterName = Nothing
    Assert.IsNull(target.ParameterName)
  End Sub

  <TestMethod()>
  Public Sub SizeTest()
    Dim target As New WmiParameter
    Assert.AreEqual(0, target.Size)
    target.Size = 24
    Assert.AreEqual(24, target.Size)
  End Sub

  <TestMethod()>
  Public Sub SourceColumnTest()
    Dim target As New WmiParameter
    Assert.IsNull(target.SourceColumn)
    target.SourceColumn = "name"
    Assert.AreEqual("name", target.SourceColumn)
    target.SourceColumn = String.Empty
    Assert.AreEqual(String.Empty, target.SourceColumn)
    target.SourceColumn = Nothing
    Assert.IsNull(target.SourceColumn)
  End Sub

  <TestMethod()>
  Public Sub SourceColumnNullMappingTest()
    Dim target As New WmiParameter
    Assert.IsFalse(target.SourceColumnNullMapping)
    target.SourceColumnNullMapping = True
    Assert.AreEqual(True, target.SourceColumnNullMapping)
  End Sub

  <TestMethod()>
  Public Sub SourceVersionTest()
    Dim target As New WmiParameter
    Assert.AreEqual(DataRowVersion.Default, target.SourceVersion)
    For Each en As DataRowVersion In [Enum].GetValues(GetType(DataRowVersion))
      target.SourceVersion = en
      Assert.AreEqual(en, target.SourceVersion)
    Next
  End Sub

  <TestMethod()>
  Public Sub ValueTest()
    Dim target As New WmiParameter
    Assert.IsNull(target.Value)
    target.Value = "value"
    Assert.AreEqual("value", target.Value)
    target.Value = String.Empty
    Assert.AreEqual(String.Empty, target.Value)
    target.Value = Nothing
    Assert.IsNull(target.Value)
    target.Value = 12
    Assert.AreEqual(12, target.Value)
    target.Value = True
    Assert.AreEqual(True, target.Value)
  End Sub
#End Region
End Class
